﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NetDiskPRJ.DBUtility;//Please add references
namespace NetDiskPRJ.DAL
{
	/// <summary>
	/// 数据访问类:PrvGroup
	/// </summary>
	public partial class PrvGroup
	{
		public PrvGroup()
		{}
        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date> 
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FGroupNo,FGroupName,FNote ");
            strSql.Append(" FROM t_PrvGroup ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date> 
        /// </summary>
        public NetDiskPRJ.Model.PrvGroup DataRowToModel(DataRow row)
        {
            NetDiskPRJ.Model.PrvGroup model = new NetDiskPRJ.Model.PrvGroup();
            if (row != null)
            {
                if (row["FGroupNo"] != null)
                {
                    model.FGroupNo = row["FGroupNo"].ToString();
                }
                if (row["FGroupName"] != null)
                {
                    model.FGroupName = row["FGroupName"].ToString();
                }
                if (row["FNote"] != null)
                {
                    model.FNote = row["FNote"].ToString();
                }
            }
            return model;
        }
         /// <summary>
        /// 是否存在该组ID记录
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public bool ExistsGrp(string groupNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_PrvGroup");
            strSql.Append(" where FGroupNo=@FGroupNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FGroupNo", SqlDbType.NVarChar,10)};
            parameters[0].Value = groupNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 增加一条数据
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public bool Add(Model.PrvGroup model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_PrvGroup(");
            strSql.Append("FGroupNo,FGroupName,FNote)");
            strSql.Append(" values (");
            strSql.Append("@FGroupNo,@FGroupName,@FNote)");
            SqlParameter[] parameters = {
					new SqlParameter("@FGroupNo", SqlDbType.NVarChar,10),
					new SqlParameter("@FGroupName", SqlDbType.NVarChar,50),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255)};
            parameters[0].Value = model.FGroupNo;
            parameters[1].Value = model.FGroupName;
            parameters[2].Value = model.FNote;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public bool Update(Model.PrvGroup model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_PrvGroup set ");
            strSql.Append("FGroupName=@FGroupName,");
            strSql.Append("FNote=@FNote");
            strSql.Append(" where FGroupNo=@FGroupNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FGroupName", SqlDbType.NVarChar,50),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FGroupNo", SqlDbType.NVarChar,10)};
            parameters[0].Value = model.FGroupName;
            parameters[1].Value = model.FNote;
            parameters[2].Value = model.FGroupNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public bool Delete(string groupNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_PrvGroup ");
            strSql.Append(" where FGroupNo=@FGroupNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FGroupNo", SqlDbType.NVarChar,10)			};
            parameters[0].Value = groupNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
	}
}

